-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up GameObjectManager::get_singleton_by_type #2986
Conversation
It had been scanning through the full list of objects, instead of looking up the singleton in m_objects_by_type_index.
117d769
to
f6b5bde
Compare
@mstoeckl Can / will you attempt the other speed improvements in subsequent pull requests? |
I'm thinking about how to do this properly at the moment. There are a few directions that I think are feasible, which have different development/maintenance/performance tradeoffs:
As writing a good spatial index may be difficult, and I don't think levels are complicated enough for this to be necessary, I currently plan to investigate option 3, and then make a PR for either 1 or 3. (Most likely option 1, since I don't want to increase development costs before Worlds 3 and 4 are complete.) Edit: went with option 1. |
Closing, this PR has been superseded. |
This mitigates a major cause of lag for me -- calls to
Sector::get_camera()
were very slow on levels with many objects, because each call ended up scanning through the full list of objects.Sector::get_camera()
gets called a lot, by everyBadGuy::is_offscreen()
and many times inParticleSystem::draw()
. The fix is to look up the singleton objects using (ultimately) them_objects_by_type_index
map.(SuperTux still has a bunch of other performance issues of this type;
GameObjectManager::get_object_count
andGameObjectManager::get_objects_by_type
are other functions that are called too often and will search the full object list instead of usingm_objects_by_type_index
or an equivalent. Long term, I'd also recommend replacingm_objects_by_type_index
with a vector indexed by an integer type ids.)